package cn.iocoder.yudao.module.trade.order.vo;

import cn.iocoder.yudao.framework.validation.InEnumValue;
import cn.iocoder.yudao.module.api.dine.enums.DineStatusEnum;
import cn.iocoder.yudao.module.api.promotion.combination.dto.CombinationRecordRespDTO;
import cn.iocoder.yudao.module.api.promotion.groupon.dto.GrouponPackageRespDTO;
import cn.iocoder.yudao.module.api.shop.info.dto.ShopInfoDTO;
import cn.iocoder.yudao.module.api.shop.staff.vo.ShopStaffVO;
import cn.iocoder.yudao.module.api.trade.order.dto.TradeOrderItemRespDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Schema(description = "用户 App - 订单交易的明细 Response VO")
@Data
public class AppTradeOrderDetailRespVO {

    // ========== 订单基本信息 ==========

    @Schema(description = "订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Long id;

    @Schema(description = "店铺编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
    private Long shopId;

    @Schema(description = "店铺信息")
    private ShopInfoDTO shop;

    @Schema(description = "交易单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1146347329394184195")
    private String no;

    @Schema(description = "订单类型：0-普通、1-秒杀、2-砍价、3-拼团、4-积分兑换、5-联盟豆兑换、6-团购、10-外送、20-美食、30-酒店、40-娱乐、50-家政、999-赠品", example = "0")
    private Integer type;

    @Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime createTime;

    @Schema(description = "商家备注", example = "你猜")
    private String remark;

    @Schema(description = "用户备注", example = "你猜")
    private String userRemark;

    @Schema(description = "订单状态：0-待付款、10-已付款（待发货、待配送、待上门）、20-进行中（运送中、配送中、服务中、待核销）、30-已完成（已收货、已服务、已取餐、已核销）、40-已关闭", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    private Integer status;

    @Schema(description = "订单状态名称", example = "待付款")
    private String statusName;

    @Schema(description = "购买的产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
    private Integer productCount;

    @Schema(description = "订单完成时间")
    private LocalDateTime finishTime;

    @Schema(description = "订单取消时间")
    private LocalDateTime cancelTime;

    @Schema(description = "是否评价", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    private Boolean commentStatus;

    @Schema(description = "评价超时时间")
    private LocalDateTime commentExpireTime;

    // ========== 价格 + 支付基本信息 ==========

    @Schema(description = "是否已支付", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
    private Boolean payStatus;

    @Schema(description = "支付单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "PAY202412011838591")
    private String payNo;

    @Schema(description = "付款时间")
    private LocalDateTime payTime;

    @Schema(description = "付款超时时间", requiredMode = Schema.RequiredMode.REQUIRED)
    private LocalDateTime payExpireTime;

    @Schema(description = "支付渠道", example = "wx_lite_pay")
    private String payChannelCode;
    @Schema(description = "支付渠道名", example = "微信小程序支付")
    private String payChannelName;

    @Schema(description = "产品原价（总）", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
    private Integer totalPrice;

    @Schema(description = "订单优惠（总）", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer discountPrice;

    @Schema(description = "运费金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer deliveryPrice;

    @Schema(description = "订单调价（总）", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer adjustPrice;

    @Schema(description = "应付金额（总）", requiredMode = Schema.RequiredMode.REQUIRED, example = "1000")
    private Integer payPrice;

    // ========== 收件 + 物流基本信息 ==========

    @Schema(description = "配送类型/服务方式：0-无、1-快递发货、2-到店自提、3-同城配送、4-现场核销、5-上门服务", example = "0")
    private Integer deliveryType;

    @Schema(description = "发货快递公司编号", example = "10")
    private Long logisticsId;

    @Schema(description = "发货物流名称", example = "顺丰快递")
    private String logisticsName;

    @Schema(description = "发货物流单号", example = "1024")
    private String logisticsNo;

    @Schema(description = "发货时间")
    private LocalDateTime deliveryTime;

    @Schema(description = "收货时间")
    private LocalDateTime receiveTime;

    @Schema(description = "收货超时时间")
    private LocalDateTime receiveExpireTime;

    @Schema(description = "收件人名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
    private String receiverName;

    @Schema(description = "收件人手机", requiredMode = Schema.RequiredMode.REQUIRED, example = "13800138000")
    private String receiverMobile;

    @Schema(description = "收件人地区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "110000")
    private Integer receiverAreaId;

    @Schema(description = "收件人地区名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "上海 上海市 普陀区")
    private String receiverAreaName;

    @Schema(description = "收件人详细地址", requiredMode = Schema.RequiredMode.REQUIRED, example = "中关村大街 1 号")
    private String receiverDetailAddress;

    @Schema(description = "自提门店编号", example = "1088")
    private Long pickUpStoreId;

    @Schema(description = "配送人员编号，外卖派单时提供", example = "1")
    private Long riderStaffId;

    @Schema(description = "配送人员编号，外卖派单时提供")
    private ShopStaffVO riderStaff;

    @Schema(description = "配送人员提交的凭证图片")
    private List<String> riderPicUrls;

    @Schema(description = "配送人员提交的备注")
    private String riderRemark;

    @Schema(description = "核销码/取件码/取餐号", example = "40964096")
    private String verifyCode;

    @Schema(description = "核销码/取件码/取餐号，BASE64格式的二维码图片数据")
    private String qrcode;

    // ========== 售后基本信息 ==========

    @Schema(description = "售后状态", example = "0")
    private Integer refundStatus;

    @Schema(description = "退款金额，单位：分", example = "100")
    private Integer refundPrice;

    // ========== 营销基本信息 ==========

    @Schema(description = "优惠劵编号", example = "1024")
    private Long couponId;

    @Schema(description = "优惠劵减免金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer couponPrice;

    @Schema(description = "VIP 减免金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "888")
    private Integer vipPrice;

    @Schema(description = "积分抵扣的金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer pointPrice;

    @Schema(description = "使用的积分", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    private Integer deductPoint;

    @Schema(description = "联盟豆抵扣的金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "100")
    private Integer cryptocurrencyPrice;

    @Schema(description = "使用的联盟豆", requiredMode = Schema.RequiredMode.REQUIRED, example = "0")
    private Integer deductCryptocurrency;

    @Schema(description = "拼团记录编号，拼团订单才有值", example = "100")
    private Long combinationRecordId;

    @Schema(description = "拼团记录，拼团订单才有值")
    private CombinationRecordRespDTO combinationRecord;

    // ========== 团购活动相关字段 ==========

    @Schema(description = "团购套餐编号，团购订单才有值")
    private Long grouponPackageId;

    @Schema(description = "团购套餐，团购订单才有值")
    private GrouponPackageRespDTO grouponPackage;

    // ========== 点餐相关字段 ==========

    @Schema(description = "点餐状态：0-无、10-待接单、20-备餐中、21-已拒单、22-已派单、30-已出餐、40-配送中、50-已送达", example = "1")
    @InEnumValue(DineStatusEnum.class)
    private Integer dineStatus;
    private String dineStatusName;

    @SuppressWarnings("unused")
    public String getDineStatusName() {
        if (dineStatusName == null) {
            return DineStatusEnum.getByValue(getDineStatus()).getName();
        }
        return dineStatusName;
    }

    @Schema(description = "接单时间，点餐下单时提供")
    private LocalDateTime acceptedTime;

    @Schema(description = "派单时间，点餐下单时提供")
    private LocalDateTime assignedTime;

    @Schema(description = "出餐时间，点餐下单时提供")
    private LocalDateTime packedTime;

    @Schema(description = "餐桌编号，点餐下单时提供", example = "0")
    private Long dineDeskId;

    @Schema(description = "用餐人数，点餐下单时提供", example = "0")
    private Integer dinePeoples;

    @Schema(description = "预定日期，预约下单才有值")
    private LocalDate reserveDate;

    @Schema(description = "预定时间段，如12:00-12:30，预约下单才有值")
    private String reservePeriod;

    /**
     * 订单项数组
     */
    private List<TradeOrderItemRespDTO> items;

}
